#include "simple_item.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ITEM_DEV "/dev/items"

void dump(const char *key, const char *val)
{
	printf("%s=%s\n", key, val);
}


int main(int ac, char *av[])
{

	char buff2[256];
	char line[256];
	char cmd;
	char key[128], val[128];
	item_init_from_file(ac > 1 ? av[1]: ITEM_DEV);
	item_traverse(dump);
	while(1){
		gets(line);
		if(line[0]=='q') break;
		memset(buff2, 0, sizeof(buff2));
		switch(line[0]){
		case 's':  // search
			sscanf(line, "%c %s", &cmd, key);
			item_string(buff2, key, 0);
			printf("query %s=%s\n", key, buff2);
			break;
		case 'c': // compare
			sscanf(line, "%c %s %s", &cmd, key, val);
			item_string(buff2, key, 0);
			printf("compare key=%s, %s ? %s\n", key, val, buff2);
			break;
		case 'l':
			item_dump();
			break;
		default:
			break;
		}
	}

	return 0;

}